# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=('nettle' 'libnettle' 'libhogweed' 'libnettle-devel')
pkgver=3.5.1
pkgrel=1
pkgdesc="A low-level cryptographic library"
arch=('i686' 'x86_64')
url="https://www.lysator.liu.se/~nisse/nettle/"
license=('GPL2')
groups=('net-utils')
depends=('gmp')
makedepends=('gmp-devel')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz{,.sig}
        nettle-2.6-msys2.patch
        3.2-dlopen-test-msys-test.patch)
validpgpkeys=('343C2FF0FBEE5EC2EDBEF399F3599FF828C67298')
sha256sums=('75cca1998761b02e16f2db56da52992aef622bf55a3b45ec538bc2eedadc9419'
            'SKIP'
            '3c83eeb093ae056ba0a583d38ed171891509ab70e39057594ee8f30885db0d99'
            'b682165983572d89c491e6d2d8307d7a04662b2de332cebd0f6766459519151c')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/nettle-2.6-msys2.patch
  patch -p1 -i ${srcdir}/3.2-dlopen-test-msys-test.patch
  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure \
    --prefix=/usr \
    --libdir=/usr/lib \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --disable-assembler

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -k check
}

package_nettle() {
  depends=('libnettle')
  install=$pkgname.install

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libnettle() {
  groups=('libraries')
  depends=('libhogweed')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*nettle*.dll ${pkgdir}/usr/bin/
}

package_libhogweed() {
  groups=('libraries')
  depends=('gmp')

  mkdir -p ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/bin/*hogweed*.dll ${pkgdir}/usr/bin/
}

package_libnettle-devel() {
  pkgdesc="Libnettle headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libnettle=${pkgver}" "libhogweed=${pkgver}" 'gmp-devel')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
